############################
# Replication file: "Insiders, outsiders, skills and preferences for social protection: evidence from a survey experiment in Argentina"
# Irene Men�ndez Gonz�lez, January 2021
############################

# Figures A3-A12 

library(readxl) 

##### Figure A3. Effect of treatment among low- and high-skilled formal workers, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A3", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov


#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA3.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.6, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skilled formal (N=222)", "High-skilled formal (N=112)", "Difference"))

dev.off()

##### Figure A4: Effect of treatment among low- and high-skilled private workers, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A4", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA4.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-1, 1), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-1, 1), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-1, 1, 0.25)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.95, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skilled private (N=146)", "High-skilled private (N=47)", "Difference"))

dev.off()


#### Fig A5: Effect of treatment for low-skill/high skill public workers, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A5", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA5.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-1, 1), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
        lines(c(-1, 1), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-1, 1, 0.25)){
        abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.95, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skilled public (N=48)", "High-skilled public (N=47)", "Difference"))
dev.off()


####### Figure A6: Treatment effects for low-skill and high-skill insiders (excluding formal self-employed and firm-owners), and their difference
####### Low-skill insiders coded as having up to incomplete secondary

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A6", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA6.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.6, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skilled insider (N=103)", "High-skilled insider (N=185)", "Difference"))
dev.off()


##### Figure A7: Effect of treatment among respondents with low- and high political knowledge, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A7", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA7.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.55, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("High knowledge (N=265)", "Low knowledge (N=69)", "Difference"))

dev.off()


##### Fig A8: Effect of treatment among individuals who declare neighbors or themselves as having received favour from candidate/not, as proxy for clientelism, and their difference 

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A8", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA8.pdf")

#Parameters of plot region, to allow for wider left margin

par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
        lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
        abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.6, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Client (N=57)", "No client (N=212)", "Difference"))
dev.off()


##### Figure A9: Treatment among those with positive and negative evaluations of Cristina Fern�ndez de Kirchner's government, and their difference 

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A9", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA9.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
        lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
        abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.6, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Positive evaluation (N=138)", "Negative evaluation (N=196)", "Difference"))

dev.off()


##### Figure A10: Treatment among insiders with positive and negative evaluations of personal economic situation (as a proxy for income), and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A10", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA10.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
        lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
        abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.6, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Positive evaluation (N=181)", "Negative evaluation (N=113)", "Difference"))

dev.off()


##### Figure A11: Treatment among low/high-skill insiders, controlling for union membership, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A11", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA11.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.55, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skill insider (N=194)", "High-skill insider (N=94)", "Difference"))
dev.off()


##### Figure A12: Treatment among low/high-skilled insiders, controlling for income, and their difference

res <- read_excel("FigA3A12Estimates.xlsx", sheet="A12", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov

#intersection of effects on y axis
yr <-  c(1.7, 1.5, 1.3)
yp <-  c(0.7, 0.5, 0.3)

t <- 1.96 #Critical t-value for 95% confidence interval

#Label for groups
group <- c("Poverty treatment", "Risk treatment")

#Commenting out printing of PDF figure
pdf("FigA12.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n", ylim=c(0,2), xlim=c(-0.6, 0.6), 
     yaxt="n", xlab="", ylab="", main = , axes=F)

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at= c(0.5, 1.5), labels=group, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less then 95%)
points(coef.risk, yr, pch= c(19, 15, 17), cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

#Same for poverty frame
points(coef.pov, yp, pch= c(19, 15, 17), cex=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in c(0.3, 0.5, 0.7, 1.3, 1.5, 1.7)){
lines(c(-0.6, 0.6), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-0.6, 0.6, 0.1)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.55, y = 2.04, pch= c(19, 15, 17), cex=0.9, legend = c("Low-skill insider (N=194)", "High-skill insider (N=94)", "Difference"))
dev.off()


